<template>
  <!-- 外层盒子 -- 预留左侧功能栏 -->
  <div class="mian-wapper">
    <!-- 报告卡 -->
    <div class="reportCard">
      <div class="title">
        <div class="titleText">
          <h2>中华人民共和国传染病报告卡</h2>
          <div class="headerBtn">
            <!-- <el-checkbox v-model="formInline.zyidType" :label="1">初次报告</el-checkbox> -->
            <!-- <el-button type="warning" size="mini">订正报卡</el-button>
            <el-button type="success" size="mini">上报空卡</el-button> -->
          </div>
        </div>
      </div>
      <!-- 报告卡表单 -->
      <el-form :model="formInline" :rules="rules" ref="reportForm" label-position="right" label-width="150px" size="small"  class="demo-form-inline">
        <!-- 基本信息 -->
        <el-card class="box-card">
          <div slot="header" class="clearfix" style="text-align: left">
            <span>基本信息</span>
          </div>
          <div class="baseInfo formItem">
            <el-row>
              <el-col :span="6">
                <el-form-item label="患者ID" label-width="90px" prop="hzId">
                  <el-input placeholder="请输入患者ID" v-model="formInline.hzId" maxlength="30" @keyup.native="getPatientInfoById" style="width:100%" :disabled="type ? true : false"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="类型" label-width="90px" prop="zyidType">
                  <el-radio v-for="item in reportTypeOp" :key="item.dictId" v-model="formInline.zyidType" border :label="parseInt(item.code)" :disabled="disabled">{{item.dictName}}</el-radio>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="科室" required prop="depart">
                  <treeselect
                    v-model="formInline.depart"
                    :clearable="true"
                    placeholder="请选择科室"
                    noChildrenText="不好意思哟~,没有下一级了~~"
                    :normalizer="normalizer"
                    :options="departOptions"
                    style="width:100%"
                    />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="门诊/住院ID" prop="zyid">
                  <el-input placeholder="请输入内容" v-model="formInline.zyid" maxlength="20" style="width:100%" :disabled="disabled"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>
        <!-- 患者信息 -->
        <el-card class="box-card">
          <div slot="header" class="clearfix" style="text-align: left">
            <span>患者信息</span>
          </div>
          <div class="patientInfo formItem">
            <el-row>
              <el-col :span="8">
                <el-form-item label="患者姓名" required label-width="90px" prop="patientname">
                  <el-input v-model="formInline.patientname" placeholder="请输入患者姓名" :disabled="disabled" ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="患者家属姓名" prop="contactname">
                  <el-input v-model="formInline.contactname" placeholder="请输入患者家属姓名" :disabled="disabled"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="性别" required prop="sex">
                  <el-radio v-for="item in sexOption" :key="item.dictId" v-model="formInline.sex" :label="item.dictName" border :disabled="disabled">{{item.dictName}}</el-radio>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="有效证件" label-width="90px" prop="cardno">
                  <el-select :disabled="disabled" v-model="formInline.cardtype" @change="changeCardType" placeholder="请选择" style="width:30%">
                      <el-option
                        v-for="item in cardTypeOptions"
                        :key="item.dictId"
                        :label="item.dictName"
                        :value="item.dictName">
                      </el-option>
                    </el-select>
                  <el-input placeholder="请输入内容" v-model="formInline.cardno" maxlength="18" @keyup.native="getBirthDay" :disabled="disabled" style="width:67%;margin-left:5px;"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="出生日期" prop="dateOfBirth">
                  <el-date-picker
                    v-model="formInline.dateOfBirth"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期"
                    :disabled="disabled"
                    :picker-options="pickerOptions0"
                    style="width:100%">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="生日不详填年龄" prop="age" >
                  <el-input type="number" v-model="formInline.age"  style="width:30%;margin-right:10px" :readonly="formInline.cardtype === '身份证' ? true : false"></el-input>
                  <el-radio v-for="item in ageUnitOption" :key="item.dictId" v-model="formInline.ageunit" border :label="parseInt(item.code)" :disabled="formInline.cardtype === '身份证' ? true : false">{{item.dictName}}</el-radio>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="联系电话" required label-width="90px" prop="tel">
                  <el-input v-model="formInline.tel" placeholder="请输入联系电话" :disabled="disabled"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="患者工作单位/学校" prop="workunitname">
                  <el-input v-model="formInline.workunitname" placeholder="请输入患者工作单位/学校" :disabled="disabled"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="单位/学校电话" prop="workunitphone">
                  <el-input v-model="formInline.workunitphone" placeholder="请输入单位/学校电话" :disabled="disabled"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <div class="secDiseasePart" v-if="istheThird">
              <el-form-item label="户籍属于" style="text-align:left" label-width="90px" prop="syphilisCensusRegister">
                <el-radio v-for="item in addressTypeOp" :key="item.dictId" v-model="formInline.syphilisCensusRegister" border :label="parseInt(item.code)" :disabled="disabled">{{item.dictName}}</el-radio>
              </el-form-item>
              <el-form-item label="户籍地址" style="text-align:left" label-width="90px" prop="syphilisRegionAddress">
                <!-- 地址选择 -->
                <address-select ref="syphilisAddressData" :realAddress.sync="domicileRealAddress" @changeAddress="changeAddress2" style="display:inline-block" :disabled="disabled" />
                <el-input v-model="formInline.syphilisRegionAddress" placeholder="请输入详细地址" style="width:38%" :disabled="disabled"></el-input>
              </el-form-item>
              <el-row>
                <el-col :span="9">
                  <el-form-item label="婚姻状况" label-width="90px" prop="marrage">
                    <el-radio v-for="item in marrayOptions" :key="item.dictId" v-model="formInline.marrage" border :label="parseInt(item.dictId)" :disabled="disabled">{{item.dictName}}</el-radio>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="民族" prop="nation" label-width="90px">
                    <el-select :disabled="disabled" v-model="formInline.nation" placeholder="请选择" style="width:100%">
                      <el-option
                        v-for="item in nationOptions"
                        :key="item.dictId"
                        :label="item.dictName"
                        :value="item.dictId">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="9">
                  <el-form-item label="文化程度" prop="education">
                    <el-select :disabled="disabled" v-model="formInline.education" placeholder="请选择" style="width:97%">
                      <el-option
                        v-for="item in cultureOptions"
                        :key="item.dictId"
                        :label="item.dictName"
                        :value="item.dictId">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
            
            <el-form-item label="参考地址" label-width="90px">
              <div class="referAddress">
                <el-input v-model="referAddress" disabled></el-input>
                <span class="tips">请按以下格式填写病人现住地址信息。包括省、市、区、街道，并详细到村组或门牌号</span>
              </div>
            </el-form-item>
            <el-form-item label="病人属于" style="text-align:left" label-width="90px" prop="arearange">
              <el-radio v-for="item in addressTypeOp" :key="item.dictId" v-model="formInline.arearange" border :label="parseInt(item.code)" :disabled="disabled">{{item.dictName}}</el-radio>
            </el-form-item>
            <el-form-item label="现住地址" style="text-align:left" label-width="90px" prop="regionAddress">
              <!-- 地址选择 -->
              <address-select ref="addressData" :realAddress.sync="realAddress" @changeAddress="changeAddress" style="display:inline-block" :disabled="disabled" />
              <el-input v-model="formInline.regionAddress" placeholder="请输入详细地址" style="width:38%" :disabled="disabled"></el-input>
            </el-form-item>
          </div>
        </el-card>
        <!-- 分行 -->
        <el-row :gutter="20">
          <!-- 分栏 -->
          <el-col :span="24">
            <!-- 疾病信息 -->
            <el-card class="box-card">
              <div slot="header" class="clearfix" style="text-align: left">
                <span>疾病信息</span>
              </div>
              <div class="diseaseInfo formItem">
                <el-row>
                  <el-col :span="16">
                    <el-form-item label="疾病名称" label-width="90px" ref="diseaseRef" prop="disease">
                      <el-radio v-model="diseaseType" :disabled="disabled" border v-for="item in diseaseNameData" :key="item.id" :label="item.id" @change="getDiseaseData(item.id)">{{item.name}}</el-radio>
                      <el-select v-if="diseaseType !== '3'" :disabled="disabled" v-model="formInline.disease" @change="getDisease" placeholder="请选择" style="width:50%; margin-left: 5px;">
                        <el-option
                          v-for="item in diseaseOptions"
                          :key="item.id"
                          :label="item.name"
                          :value="item.name">
                        </el-option>
                      </el-select>
                      <el-input v-if="diseaseType === '3'" placeholder="其他疾病详情" :disabled="disabled" v-model="formInline.disease" style="width:50%; margin-left: 5px;"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!-- 二类 疾病时，出现以下字段 -->
                <div class="secDiseasePart" v-if="istheThird">
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="接触史" label-width="130px" prop="contact">
                        <el-select v-model="formInline.contact" multiple placeholder="请选择" style="width:98%" :disabled="disabled">
                          <el-option
                            v-for="item in contactTypeOptions"
                            :key="item.dictId"
                            :label="item.dictName"
                            :value="item.dictName">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6" v-if="formInline.contact.indexOf('注射毒品史') > -1">
                      <el-form-item label="与患者共用过注射器的人数" required label-width="230px" prop="injectCount">
                        <el-input-number :disabled="disabled" v-model="formInline.injectCount" style="width:97%;" :min="1" ></el-input-number>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="formInline.contact.indexOf('非婚异性性接触史') > -1">
                      <el-form-item label="与患者有非婚性行为的人数" required label-width="230px" prop="nonwebCount">
                        <el-input-number :disabled="disabled" v-model="formInline.nonwebCount" style="width:100%;" :min="1" ></el-input-number>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="formInline.contact.indexOf('男男性行为史') > -1">
                      <el-form-item label="与患者发生同性性行为的人数" required label-width="230px" prop="smCount">
                        <el-input-number :disabled="disabled" v-model="formInline.smCount" style="width:100%;" :min="1" ></el-input-number>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6" v-if="formInline.contact.indexOf('其他') > -1">
                      <el-form-item label="其他接触史" required label-width="130px" prop="contactOther">
                        <el-input :disabled="disabled" v-model="formInline.contactOther" style="width:90%;"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="性病史" required label-width="130px" prop="venerealDisCode">
                        <el-select v-model="formInline.venerealDisCode" placeholder="请选择" style="width:100%" :disabled="disabled">
                          <el-option
                            v-for="item in venerealDisOptions"
                            :key="item.dictId"
                            :label="item.dictName"
                            :value="item.dictName">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="样本来源" required label-width="90px" prop="discoveryModeCode">
                        <el-select v-model="formInline.discoveryModeCode" placeholder="请选择" :style="{width:formInline.discoveryModeCode === '其他' ? '44%' : '100%'}" :disabled="disabled">
                          <el-option
                            v-for="item in discoveryModeOptions"
                            :key="item.dictId"
                            :label="item.dictName"
                            :value="item.dictName">
                          </el-option>
                        </el-select>
                        <el-input v-if="formInline.discoveryModeCode === '其他'" placeholder="其他样本来源" :disabled="disabled" v-model="formInline.discoveryModeOther" style="width:53%; margin-left: 5px;"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10">
                      <el-form-item label="最有可能感染途径" label-width="240px" prop="bsTransmissionCode">
                        <el-select v-model="formInline.bsTransmissionCode" placeholder="请选择" :style="{width:formInline.bsTransmissionCode === '其他' ? '42%' : '94%'}" :disabled="disabled">
                          <el-option
                            v-for="item in bsTransmissionOptions"
                            :key="item.dictId"
                            :label="item.dictName"
                            :value="item.dictName">
                          </el-option>
                        </el-select>
                        <el-input v-if="formInline.bsTransmissionCode === '其他'" placeholder="其他感染途径" :disabled="disabled" v-model="formInline.bsTransmissionOther" style="width:48%; margin-left: 5px;"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="实验室检测结论" required label-width="130px" prop="laboratoryDetectionVerdictCode">
                        <el-select v-model="formInline.laboratoryDetectionVerdictCode" placeholder="请选择" style="width:100%" :disabled="disabled">
                          <el-option
                            v-for="item in laboratoryDetectionVerdictOptions"
                            :key="item.dictId"
                            :label="item.dictName"
                            :value="item.dictName">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="确认(替代策略、核酸）检测阳性日期" required label-width="260px" prop="detectionPositiveDate">
                        <el-date-picker
                          v-model="formInline.detectionPositiveDate"
                          type="date"
                          placeholder="选择日期"
                          value-format="yyyy-MM-dd"
                          :disabled="disabled"
                          :picker-options="pickerOptions0"
                          style="width:100%">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10">
                      <el-form-item label="确认(替代策略、核酸）检测单位" required label-width="240px" prop="detectionOrg">
                        <el-input placeholder="检测单位" :disabled="disabled" v-model="formInline.detectionOrg" style="width:94%"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="人群分类" required label-width="90px" prop="profession">
                      <el-select v-model="formInline.profession" placeholder="请选择" style="width:97%" :disabled="disabled">
                        <el-option
                          v-for="item in personClassic"
                          :key="item.dictId"
                          :label="item.dictName"
                          :value="item.dictId">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="index === 0 ? 7 : 9" v-for="(item, index) in infectioustypeOption" :key="item.id">
                    <el-form-item :label="item.name" required :rules="{ required: true, message: '选择疾病分类', trigger: 'blur' }">
                      <el-select v-model="infectioustype[index]" :disabled="disabled" @change="setValue" placeholder="请选择" style="width:50%">
                        <el-option
                          v-for="item2 in item.children"
                          :key="item2.id"
                          :label="item2.name"
                          :value="item2.id">
                        </el-option>
                      </el-select>
                      <span class="caseTips spanText">({{item.description}})</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="发病日期" required label-width="90px" prop="morbidityDate">
                      <el-date-picker
                        v-model="formInline.morbidityDate"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        :disabled="disabled"
                        :picker-options="pickerOptions0"
                        style="width:50%">
                      </el-date-picker>
                      <span class="spanText">(病原携带者请填写诊断时间)</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7">
                    <el-form-item label="诊断时间" required prop="disgnoseDate">
                      <el-date-picker
                        v-model="formInline.disgnoseDate"
                        type="datetime"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        :disabled="disabled"
                        :picker-options="pickerOptions0"
                        style="width:100%">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="9">
                    <el-form-item label="死亡时间"  prop="deathdate">
                      <el-date-picker
                        v-model="formInline.deathdate"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        :disabled="disabled"
                        :picker-options="pickerOptions0"
                        style="width:100%">
                      </el-date-picker>
                      <!-- <el-input v-model="formInline.deathdate" style="width:49%"></el-input> -->
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="密切接触者相同症状" required label-width="160px" prop="contactsymptoms">
                      <el-radio v-model="formInline.contactsymptoms" border :label="1" :disabled="disabled">有</el-radio>
                      <el-radio v-model="formInline.contactsymptoms" border :label="0" :disabled="disabled">无</el-radio>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7" v-if="formInline.disease === '198手足口病'">
                    <el-form-item label="重症患者" required prop="handFootMouthDiseaseSevere">
                      <el-radio v-model="formInline.handFootMouthDiseaseSevere" border :label="0" :disabled="disabled">否</el-radio>
                      <el-radio v-model="formInline.handFootMouthDiseaseSevere" border :label="1" :disabled="disabled">是</el-radio>
                    </el-form-item>
                  </el-col>
                  <el-col :span="9" v-if="formInline.disease === '198手足口病'">
                    <el-form-item  label="实验室结果" required prop="experimentalResults">
                      <el-select :disabled="disabled" v-model="formInline.experimentalResults" placeholder="请选择" style="width:100%;">
                        <el-option
                          v-for="item in labResultOptions"
                          :key="item.dictId"
                          :label="item.dictName"
                          :value="item.dictId">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <!-- 医生信息 -->
        <el-row>
          <!-- 分栏 -->
          <el-col :span="24">
            <!-- 疾病信息 -->
            <el-card class="box-card">
              <div slot="header" class="clearfix" style="text-align: left">
                <span>医生信息</span>
              </div>
              <div class="diseaseInfo formItem">
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="报告科室" required label-width="90px" prop="reportDepartment">
                      <el-input v-model="formInline.reportDepartment"  placeholder="请输入科室" :disabled="disabled"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7">
                    <el-form-item label="报告医生" required prop="reportDoctorName">
                      <el-input v-model="formInline.reportDoctorName" placeholder="请输入医生姓名" :disabled="disabled"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="9">
                    <el-form-item label="联系电话" prop="reportDoctorPhone">
                      <el-input v-model="formInline.reportDoctorPhone" placeholder="请输入医生电话" :disabled="disabled"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="备注" label-width="90px" prop="notes">
                      <el-input type="textarea" placeholder="备注" rows="2" v-model="formInline.notes" :disabled="disabled"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <!-- 按钮 -->
        <el-form-item label-width="0px">
          <el-button v-if="type !== '1'" type="primary" @click="reportCard">提交上报</el-button>
          <el-button v-if="type && type !== '1'" type="warning" @click="handleAudit">审 核</el-button>
          <el-button v-if="type === '1'" type="primary" @click="closeCard">关 闭</el-button>
        </el-form-item>
      </el-form>
      <!-- 审核提交框 -->
      <view-dialog ref="viewDialog" @handleReportView="closeWindow"></view-dialog>
    </div>
  </div>
</template>

<script>
import { reportCard, diseaseData, getInfectiousData, getAddress, getPatientInfoById, getBirthByCardId, getDepartData } from '@/api/hospital/index'
import { validateCardno, checkNum, checkPhoneNum, checkTime, checkDepart } from '@/utils/validateRules.js'
import { cardDataEcho, editReportCard } from '@/api/hospital/reportreview.js'
import { getDictDataByCode } from '@/api/auth/dict.js'
import AddressSelect from './components/address'
import { formatToDate } from '@/utils/datetime.js'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import viewDialog from './components/viewDialog'
export default {
  data () {
    return {
      disabled: false,
      // 科室数据
      departOptions: [],
      // 参考地址
      referAddress: '重庆市沙坪坝区陈家桥镇廖家平安置区附29栋3-1',
      // 国际地址 -- 省、市、区、县、镇
      realAddress: {
        province: '',
        city: '',
        area: '',
        town: ''
      },
      // 户籍地址选择
      domicileRealAddress: {
        province: '',
        city: '',
        area: '',
        town: ''
      },
      // 上报类型 -- 门诊/住院
      reportTypeOp: [],
      cardTypeOptions: [],
      // 性别下拉选数据
      sexOption: [],
      // 年龄单位下拉选数据
      ageUnitOption: [],
      // 病人属于 -- 地址类型
      addressTypeOp: [],
      // 婚姻
      marrayOptions: [],
      // 民族
      nationOptions: [],
      // 文化程度
      cultureOptions: [],
      // 人群分类
      personClassic: [],
      // 病例分类
      infectioustypeOption: {},
      // 疾病名称数据
      diseaseNameData: [],
      // 疾病名称下拉选数据
      diseaseOptions: [],
      diseaseType: '1',
      infectioustype: [],
      // 接触史下拉框数据
      contactTypeOptions: [],
      // 性病史下拉框数据
      venerealDisOptions: [],
      // 最有可能感染途径
      bsTransmissionOptions: [],
      // 样本来源
      discoveryModeOptions: [],
      // 实验室检测结论
      laboratoryDetectionVerdictOptions: [],
      // 实验室结果 三类（手足口病）
      labResultOptions: [],
      // 审核界面点击查看过来的id
      auditId: '',
      // 审计界面传过来的 -- 修改/查看
      type: '',
      // 是否是第三种类型的疾病
      istheThird: false,
      // 诊断时间 小时
      formInline: {
        hzId: '',
        zyidType: 1,
        depart: null,
        zyid: '',
        patientname: '',
        contactname: '',
        sex: '女',
        cardtype: '身份证',
        cardno: '',
        dateOfBirth: '',
        age: '',
        ageunit: 1,
        tel: '',
        workunitname: '',
        workunitphone: '',
        arearange: 1,
        address: '',
        regionAddress: '',
        profession: '',
        disease: '',
        infectioustype: '',
        morbidityDate: '',
        disgnoseDate: '',
        deathdate: '',
        contactsymptoms: 1,
        reportDepartment: '',
        reportDoctorName: '',
        reportDoctorPhone: '',
        notes: '',
        // 二类疾病增加的字段
        syphilisCensusRegister: 1,
        syphilisAddress: '',
        syphilisRegionAddress: '',
        marrage: '',
        nation: '',
        education: '',
        contact: '',
        injectCount: '',
        nonwebCount: '',
        smCount: '',
        contactOther: '',
        venerealDisCode: '',
        bsTransmissionCode: '',
        bsTransmissionOther: '',
        discoveryModeCode: '',
        discoveryModeOther: '',
        laboratoryDetectionVerdictCode: '',
        detectionPositiveDate: '',
        detectionOrg: '',
        // 三类 -- 手足口病增加的字段
        handFootMouthDiseaseSevere: 0,
        experimentalResults: ''
      },
      rules: {
        depart: [
          { required: true, message: '请选择科室', trigger: 'blur' },
          { validator: checkDepart, trigger: 'blur' }
        ],
        zyid: [
          { required: true, message: '门诊/住院ID不能为空', trigger: 'blur' }
        ],
        patientname: [
          { required: true, message: '患者姓名不能为空', trigger: 'blur' }
        ],
        contactname: [
          { required: true, message: '患者家属不能为空', trigger: 'blur' }
        ],
        cardno: [
          { required: true, message: '请输入证件号码', trigger: 'blur' }
        ],
        dateOfBirth: [
          { required: true, message: '请输入出生日期', trigger: 'blur' }
        ],
        age: [
          { required: true, message: '请输入年龄', trigger: 'blur' },
          { validator: checkNum, trigger: 'blur' }
        ],
        tel: [
          { required: true, message: '请输入联系电话', trigger: 'blur' },
          { validator: checkPhoneNum, trigger: 'blur' }
        ],
        workunitname: [
          { required: true, message: '请输入患者单位/学校', trigger: 'blur' }
        ],
        marrage: [
          { required: true, message: '请选择婚姻状况', trigger: 'blur' },
        ],
        address: [
          { required: true, message: '国际地址不能为空', trigger: 'blur' }
        ],
        regionAddress: [
          { required: true, message: '地址不能为空', trigger: 'blur' }
        ],
        profession: [
          { required: true, message: '请选择人群分类', trigger: 'blur' }
        ],
        disease: [
          { required: true, message: '请选择疾病名称', trigger: 'blur' }
        ],
        morbidityDate: [
          { required: true, message: '请选择发病时间', trigger: 'blur' },
          { validator: checkTime, trigger: 'blur' }
        ],
        disgnoseDate: [
          { required: true, message: '请选择诊断时间', trigger: 'blur' },
          { validator: checkTime, trigger: 'blur' }
        ],
        deathdate: [
          { validator: checkTime, trigger: 'blur' }
        ],
        reportDoctorName: [
          { required: true, message: '报告医生不能为空', trigger: 'blur' }
        ],
        reportDepartment: [
          { required: true, message: '报告科室不能为空', trigger: 'blur' }
        ],
        contact: [
          { required: true, message: '接触史不能为空', trigger: 'blur' }
        ]
      },
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() >= Date.now() - 8.64e6
        }
      },
      normalizer(node) {
        return {
          id: node.fullName,
          label: node.fullName
        }
      }
    }
  },
  components: {
    AddressSelect,
    Treeselect,
    viewDialog
  },
  created() {
    // 科室数据
    this.getDepartData()
    // 上报类型
    this.getDictByCode('reportTypeOp', 'reportType')
    // 证件类型
    this.getDictByCode('cardTypeOptions', 'cardType')
    // 性别
    this.getDictByCode('sexOption', 'sex')
    // 年龄单位
    this.getDictByCode('ageUnitOption', 'ageUnit')
    // 地址类型
    this.getDictByCode('addressTypeOp', 'addressType')
    // 人群分类
    this.getDictByCode('personClassic', 'personType')
    // 婚姻状况
    this.getDictByCode('marrayOptions', 'marriage')
    // 民族
    this.getDictByCode('nationOptions', 'nation')
    // 学历
    this.getDictByCode('cultureOptions', 'culture')

    // 接触史下拉框数据
    this.getDictByCode('contactTypeOptions', 'ContactTypeCode')
    // 性病史下拉框数据
    this.getDictByCode('venerealDisOptions', 'VenerealDisCode')
    // 最有可能感染途径
    this.getDictByCode('bsTransmissionOptions', 'BsTransmissionCode')
    // 样本来源
    this.getDictByCode('discoveryModeOptions', 'DiscoveryModeCode')
    // 实验室检测结论
    this.getDictByCode('laboratoryDetectionVerdictOptions', 'LaboratoryDetectionVerdictCode')
    // 实验室结果 三类（手足口病）
    this.getDictByCode('labResultOptions', 'LabResultCode')

    // 病例名称
    this.getDiseaseData(0)
    // 病例分类
    this.getInfectiousType(0, 0)
    // 审核界面修改/查看传的参数
    this.type = this.$route.query.type
    this.auditId = this.$route.query.id
    // 类型为1（查看）禁用所有表单输入
    if (this.type === '1') this.disabled = true
    // 修改 查询数据回显
    if (this.auditId !== undefined) {
      this.handleDataById()
    } else {
      // 根据病人id获取信息
      // this.getPatientInfoById()
    }
  },
  methods: {
    // 根据字典编码查询字典数据
    async getDictByCode (params, code) {
      await getDictDataByCode(code).then(res => {
        if (res.code === 200) this.$data[params] = res.data
      })
    },
    // 获取科室数据
    getDepartData () {
      this.departOptions = []
      getDepartData().then((res) => {
        if (res.code === 200) {
          this.departOptions = res.data
        }
      })
    },
    // 根据病人id获取数据
    getPatientInfoById () {
      getPatientInfoById(this.formInline.hzId)
      .then(res => {
        if (res.code === 200) {
          res.data.disgnoseDate = res.data.disgnoseDate + ' 00:00:00'
          Object.assign(this.formInline, res.data)
          this.formInline.reportDoctorName = res.data.doctorName
          // 重新获取年龄 -- 根据身份证号获取
          this.getBirthDay()
        }
      })
    },
    // 切换证件类型时
    changeCardType (val) {
      this.formInline.cardno = ''
      this.formInline.dateOfBirth = ''
      this.formInline.age = ''
      this.formInline.ageunit = 1
    },
    // 根据证件号码 获取出生日期
    getBirthDay () {
      // 当输入的证件号码有18位时
      if (this.formInline.cardno.length === 18 && this.formInline.cardtype === '身份证') {
        getBirthByCardId(this.formInline.cardno).then(res => {
          if (res.code === 200) {
            this.formInline.dateOfBirth = res.data.birthday
            this.formInline.age = res.data.age
            this.formInline.ageunit = parseInt(res.data.unit)
          }
        })
      }
    },
    // 获取疾病名称
    async getDiseaseData (id) {
      this.formInline.disease = ''
      await diseaseData({pid:id}).then(res => {
        if (res.code === 200) {
          // id === 0 查询第一级疾病名称分类
          if (id === 0) {
            this.diseaseNameData = res.data
            this.getDiseaseData(res.data[0].id)
          } else { // 查询第二级
            this.diseaseOptions = res.data
          }
        }
      })
    },
    // 疾病名称不同加载不同的样式
    getDisease (val) {
      if (val === '19Ⅱ期梅毒' || val === '200Ⅲ期梅毒' || val === '201胎传梅毒' || val === '321隐性梅毒' || val === '145尖锐湿疣' || val === '144非淋菌性展道炎'){
        this.istheThird = true
      } else {
        if (val === '198手足口病'){
          // 默认重症患者选项为否
          this.formInline.handFootMouthDiseaseSevere = 0
          this.formInline.experimentalResults = ''
        }
        this.istheThird = false
      }
    },
    // 获取病例分类
    getInfectiousType (id, type) {
      // 清空数据
      this.infectioustypeOption = {}
      getInfectiousData().then(res => {
        if (res.code === 200) {
          this.infectioustypeOption = res.data
        }
      })
    },
    // 根据id获取信息
    handleDataById() {
      cardDataEcho(this.auditId).then((res) => {
        if (res.code === 200) {
          // 分割地址字段
          let address = res.data.address.split(',')
          this.realAddress.province = address[0]
          this.realAddress.city = address[1]
          this.realAddress.area = address[2]
          this.realAddress.town = address[3]
          this.$refs.addressData.init(this.realAddress)
          // 数据回显
          this.formInline = { ...res.data }
          this.formInline.profession = res.data.profession.toString()
          // 重新获取年龄 -- 根据身份证号获取
          this.getBirthDay()
          // 疾病名称
          this.diseaseType = res.data.disease.split(',')[0]
          this.getDiseaseData(this.diseaseType ? this.diseaseType : 0)
          // 解决疾病名称回显时数据不显示的问题
          let _this = this
          setTimeout(function() {
            _this.formInline.disease = res.data.disease.split(',')[1]
            // 根据疾病名称显示不同的上报字段
            _this.getDisease(_this.formInline.disease)
            // 等待疾病名称加载出来后再回显数据
            _this.formInline.handFootMouthDiseaseSevere = res.data.handFootMouthDiseaseSevere
            _this.formInline.experimentalResults = res.data.experimentalResults
          }, 200)
          // 疾病为梅毒等第二类疾病时，才回显的数据
          this.formInline.marrage = parseInt(res.data.marrage)
          this.formInline.contact = res.data.contact ? res.data.contact.split(',') : ''
          this.formInline.syphilisCensusRegister = this.formInline.syphilisCensusRegister ? parseInt(this.formInline.syphilisCensusRegister) : ''
          if (res.data.syphilisAddress) {
            this.domicileRealAddress.province = res.data.syphilisAddress.split(',')[0]
            this.domicileRealAddress.city = res.data.syphilisAddress.split(',')[1]
            this.domicileRealAddress.area = res.data.syphilisAddress.split(',')[2]
            this.domicileRealAddress.town = res.data.syphilisAddress.split(',')[3]
            setTimeout(function(){
              _this.$refs.syphilisAddressData.init(_this.domicileRealAddress)
            }, 200)
          }
          // 病例分类
          this.infectioustype = res.data.infectioustype.split(',')
        }
      })
    },
    // 更新地址
    changeAddress (val) {
      this.realAddress = {...val}
    },
    // 梅毒类疾病的地址
    changeAddress2 (val) {
      this.domicileRealAddress = {...val}
    },
    // 选择时获取焦点
    setValue (val) {
      this.$forceUpdate()
    },
    // 关闭上报卡
    closeCard() {
      setTimeout(() => {
        window.close()
        window.location.hash = '#/hospital/reportReview'
      }, 500)
    },
    // 修改的时候 -- 疾病名称有梅毒变为其他，需要清空梅毒相关的字段信息
    clearSyphilisData () {
      // 第三种疾病
      if (!this.istheThird) {
        this.formInline.marrage = ''
        this.formInline.nation = ''
        this.formInline.education = ''
        this.formInline.syphilisCensusRegister = ''
        this.formInline.syphilisAddress = ''
        this.formInline.syphilisRegionAddress = ''
        this.formInline.contact = ''
        this.formInline.injectCount = ''
        this.formInline.nonwebCount = ''
        this.formInline.smCount = ''
        this.formInline.contactOther = ''
        this.formInline.venerealDisCode = ''
        this.formInline.bsTransmissionCode = ''
        this.formInline.bsTransmissionOther = ''
        this.formInline.discoveryModeCode = ''
        this.formInline.discoveryModeOther = ''
        this.formInline.laboratoryDetectionVerdictCode = ''
        this.formInline.detectionPositiveDate = ''
        this.formInline.detectionOrg = ''
        this.domicileRealAddress = {
          province: '',
          city: '',
          area: '',
          town: ''
        }
      }
      if (this.formInline.disease !== '198手足口病') {
        this.formInline.handFootMouthDiseaseSevere = 0
        this.formInline.experimentalResults = ''
      }
    },
    // 提交
    reportCard () {
      // 清空数据
      this.clearSyphilisData()
      let data = {...this.formInline}
      // 病例分类
      data.infectioustype = this.infectioustype ? this.infectioustype.join(',') : ''
      // 疾病名称
      data.disease = this.diseaseType + ',' + this.formInline.disease
      // 国际地址
      data.address = this.realAddress.province + ',' + this.realAddress.city + ',' + this.realAddress.area + ',' + this.realAddress.town
      data.syphilisAddress = this.domicileRealAddress.province ? (this.domicileRealAddress.province + ',' + this.domicileRealAddress.city + ',' + this.domicileRealAddress.area + ',' + this.domicileRealAddress.town ) : ''
      data.contact = data.contact ? data.contact.join(',') : ''
      // 验证表单
      this.$refs.reportForm.validate((valid) => {
        if (valid) {
          if (this.auditId !== undefined) { // 修改
            editReportCard(data).then((res) => {
              if (res.code === 200) {
                if (this.$refs.reportForm !==undefined) {
                  this.$refs.reportForm.resetFields()
                  setTimeout(() => {
                    window.close()
                    window.history.back(-1)
                    // window.location.hash = '#/hospital/reportReview'
                  }, 500)
                }
              }
            })
          } else { // 新增
            reportCard(data).then(res => {
              if (res.code === 200) {
                if (this.$refs.reportForm !==undefined) {
                  // 去除验证方法
                  this.$refs.reportForm.clearValidate()
                  // 清空数据
                  this.infectioustype = []
                   for (let key in this.realAddress) {
                    this.realAddress[key] = ''
                  }
                  this.$refs.addressData.clearAddress()
                  this.$refs.reportForm.resetFields()
                  this.formInline.disease = ''
                  this.istheThird = false
                }
              }
            })
          }
        }
      })
    },
    // 审核
    handleAudit() {
      this.$refs.viewDialog.init(this.auditId, true)
    },
    // 关闭上报卡
    closeWindow() {
      setTimeout(() => {
        window.close()
        window.history.back(-1)
      }, 500)
    }
  }
}
</script>

<style lang="scss" scoped>
  .el-row {
    text-align: left;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .boxCard{
    // height: 50px;
    border: 1px solid #EBEEF5;
    background-color: #FFF;
    color: #303133;
    -webkit-transition: .3s;
    transition: .3s;
    border-radius: 4px;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
    .card-header{
      text-align: left;
      padding: 6px 20px;
      font-size: 14px;
      border-bottom: 1px solid #EBEEF5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
    }
    .baseInfo{
      padding: 20px;
    }
  }
  .box-card {
    // margin-bottom: 20px;
    overflow: visible;
  }
  .reportCard{
    padding: 0 10px 10px 10px;
    overflow: hidden;
    // background: #ccc;
  }
  .titleText {
    position: relative;
    // width: 400px;
    margin: 0 auto;
    text-align: center;
    h2{
      font-size: 24px;
    }
    .headerBtn {
      position: absolute;
      top: 10px;
      left: 400px;
      width: 300px;
    }
  }

  .referAddress{
    padding: 5px;
    text-align: left;
    background: #f0f0f0;
    span{
      font-size: 12px;
    }
  }
  span.spanText{
    // display: block;
    font-size: 12px;
    &.caseTips{
      color: red;
    }
  }
  .secDiseasePart{
    width: 100%;
    padding-top: 10px;
    margin-bottom: 10px;
    border: 1px dashed #ccc;
  }
</style>
